

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.*;
import java.util.Random;
import java.util.Scanner;

public class Main {
    static Scanner sc=new Scanner(System.in);
    static Connection con;
    static PreparedStatement ps=null,ps1=null,ps2=null,ps3=null,ps4=null;
    Statement ss=null;
    static ResultSet rs=null,rs1=null,rs2=null,rs3=null;





    public static void main(String[] args) throws Exception {
        Connect connect=new Connect();
        con=connect.getConnection();
        while(true){
            System.out.println("*********欢迎使用健身房信息管理系统**********");
            System.out.println("请选择你的身份登陆");
            System.out.println("1：管理员登陆");
            System.out.println("2：会员登陆");
            System.out.println("3：退出");
            int a=sc.nextInt();
            switch (a){
                case 1:ManagerMenu();break;
                case 2:MemberMenu();break;
                case 3:return;
            }
        }


    }
    public static void MemberMenu() throws SQLException {
        System.out.println("");
        System.out.println("");
        System.out.println("请输入会员账号：");
        String s=sc.next();
        System.out.println("请输入密码");
        String s1=sc.next();
        int flag=1;
        try{
            String sql="select * from members where Account=? and Password=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,s);
            ps.setString(2,s1);
            rs=ps.executeQuery();
            while(rs.next()) {
                flag=0;
            }
            ps.close();
            rs.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(flag==1){
            System.out.println("帐号或密码有误请重新登陆！");
            return;
        }
        System.out.println("请选择你要执行的操作：");
        System.out.println("1：会员上课");
        System.out.println("2：个人信息修改");
        System.out.println("3：查看已报课程");
        System.out.println("4：退出");
        int b=sc.nextInt();
        switch(b){
            case 1:Study(s);break;
            case 2:UpdateSelf(s);break;
            case 3:MyCourse(s);break;
            case 4:return;
        }



    }

    private static void MyCourse(String s) throws SQLException {
        String sql="select * from message where Account=?";
        ps=con.prepareStatement(sql);
        ps.setString(1,s);
        rs=ps.executeQuery();
        while(rs.next()){
            String sql1="select * from course where Number=?";
            ps1=con.prepareStatement(sql1);
            ps1.setString(1,rs.getString("Number"));
            rs1=ps1.executeQuery();
            System.out.println("Number" + "   " + "courseName" + "   " + "Coach" + "   " + "Time"+ "    " +"Date"+"     "+"Price");
            while(rs1.next()){
                String num=rs1.getString("Number");
                String name=rs1.getString("courseName");
                String coach=rs1.getString("Coach");
                String time=rs1.getString("Time");
                String date=rs1.getString("Date");
                Double price=rs1.getDouble("Price");
                System.out.println(num+"       "+name+"     "+coach+"   "+time+"   "+date+"     "+price);
            }
            ps1.close();
            rs1.close();
        }
        ps.close();
        rs.close();
    }

    public static void UpdateSelf(String acc) {
        System.out.println("查看当前信息:");
        int flag=1;
        try {
            String sql="select * from members where Account=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Account" + "    " +"Password"+ "     " + "Name" + "        " + "Sex" + "   " +"Tel"+ "         " + "Balance");
                System.out.println(rs.getString("Account")+"     "+rs.getString("Password")+"     "+rs.getString("Name")+"\t"+rs.getString("Sex")+"\t"+rs.getString("Tel")+"     "+rs.getDouble("Balance"));
                flag=0;
            }
            if(flag==1) {
                System.out.println("查无此人！");
            }
            System.out.println("请输入修改后的信息：");
            System.out.println("密码:");
            String pass = sc.next();
            System.out.println("名字:");
            String name = sc.next();
            System.out.println("性别:");
            String sex = sc.next();
            System.out.println("电话:");
            String tel = sc.next();
            String sql1="update members set Password=?,Name=?,Sex=?,Tel=? where Account=?";
            ps=con.prepareStatement(sql1);
            ps.setString(1,pass);
            ps.setString(2,name);
            ps.setString(3,sex);
            ps.setString(4,tel);
            ps.setString(5,acc);
            int t=ps.executeUpdate();
            if(t>0) {
                System.out.println("修改信息成功！");
            }else {
                System.out.println("修改信息失败！");
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void Study(String acc) throws SQLException {
        System.out.println("Number" + "   " + "courseName" + "   " + "Coach" + "   " + "Time"+ "    " +"Date"+"     "+"Price");
        String sql="select * from course";
        try{
            ps=con.prepareStatement(sql);
            rs=ps.executeQuery();

            while(rs.next()) {
                String num=rs.getString("Number");
                String name=rs.getString("courseName");
                String coach=rs.getString("Coach");
                String time=rs.getString("Time");
                String date=rs.getString("Date");
                Double price=rs.getDouble("Price");
                System.out.println(num+"       "+name+"     "+coach+"   "+time+"   "+date+"     "+price);
            }
            rs.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("请输入您要报名上课的课程对应的编号：");
        String ss=sc.next();
        String sql1="select * from message where Account=? and Number=?";
        ps2=con.prepareStatement(sql1);
        ps2.setString(1,acc);
        ps2.setString(2,ss);
        rs2=ps2.executeQuery();
        int f=1;
        while(rs2.next()) {
            f=0;
            System.out.println("您已报名过该课程");
        }
        if(f==1) {
            String sql3="select * from course where Number=?";
            ps1=con.prepareStatement(sql3);
            ps1.setString(1,ss);
            rs1=ps1.executeQuery();
            String time=new String();
            while(rs1.next()){
                time=rs1.getString("Date");
            }
            String sql2="select * from message where Account=?";
            ps3=con.prepareStatement(sql2);
            ps3.setString(1,acc);
            rs3=ps3.executeQuery();
            int fl=1;
            while(rs3.next()){
                if(rs3.getString("Date").equals(time)){
                    System.out.println("您已报名的课程与该课程时间冲突，请重新选择！");
                    fl=0;
                    return;
                }
            }
            if(fl==1){
                String sql4="insert into message(Account,Number,Date) values(?,?,?)";
                ps4=con.prepareStatement(sql4);
                ps4.setString(1,acc);
                ps4.setString(2,ss);
                ps4.setString(3,time);
                if(!ps4.execute())
                {
                    System.out.println("添加课程信息成功！");
                    return;
                }
                else
                {
                    System.out.println("添加课程信息失败！");
                }
                ps4.close();

            }
        }

    }

    public static void ManagerMenu() {
        System.out.println("");
        System.out.println("");
        System.out.println("请输入管理员账号：");
        String s=sc.next();
        System.out.println("请输入密码");
        String s1=sc.next();
        int flag=1;
        try{
            String sql="select * from manager where Account=? and Password=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,s);
            ps.setString(2,s1);
            rs=ps.executeQuery();
            while(rs.next()) {
                flag=0;
            }
            ps.close();
            rs.close();

        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(flag==1){
            System.out.println("帐号或密码有误请重新登陆！");
            return;
        }
        while(true){
            System.out.println("请选择你要执行的操作：");
            System.out.println("1：各种信息的统计");
            System.out.println("2：会员信息管理");
            System.out.println("3：课程信息管理");
            System.out.println("4：教练信息管理");
            System.out.println("5：退出");
            int b=sc.nextInt();
            switch(b){
                case 1:Statistic();break;
                case 2:MemberLogin();break;
                case 3:CourseLogin();break;
                case 4:CoachLogin();break;
                case 5:return;
            }
        }

    }

    private static void Statistic() {
        int a=0;
        int b=0;
        int c=0;
        String sql1="select * from members";
        try{
            ps=con.prepareStatement(sql1);
            rs=ps.executeQuery();

            while(rs.next()) {
                a++;
            }
            rs.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        String sql2="select * from course";
        try{
            ps1=con.prepareStatement(sql2);
            rs1=ps1.executeQuery();

            while(rs1.next()) {
                b++;
            }
            rs1.close();
            ps1.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        String sql3="select * from coach";
        try{
            ps2=con.prepareStatement(sql3);
            rs2=ps2.executeQuery();

            while(rs2.next()) {
                c++;
            }
            rs2.close();
            ps2.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("本健身房各人员数量统计：");
        System.out.println("会员："+a+"人"+"   "+"健身课程："+b+"人"+"   "+"健身教练："+c+"人");
    }

    public static void MemberLogin() {
        System.out.println("请选择你要执行的操作：");
        System.out.println("1：浏览所有会员信息");
        System.out.println("2：增加会员信息");
        System.out.println("3：删除会员信息");
        System.out.println("4：查询会员信息");
        System.out.println("5：修改会员信息");
        System.out.println("6：退出");
        int x=sc.nextInt();
        switch(x){
            case 1:ShowMembers();break;
            case 2:AddMembers();break;
            case 3:DeleteMembers();break;
            case 4:QueryMembers();break;
            case 5:UpdateMembers();break;
            case 6:return;
        }

    }

    public static void QueryMembers() {
        System.out.println("请输入查找会员信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from members where Account=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Account" + "     " + "Name" + "   " + "Sex" + "     " + "Tel"+ "     " +"Balance");
                System.out.println(rs.getString("Account")+"     "+rs.getString("Name")+"\t"+rs.getString("Sex")+"\t"+rs.getString("Tel")+"\t"+rs.getDouble("Balance"));
                flag=0;
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
        if(flag==1) {
            System.out.println("查无此人！");
        }
    }

    public static void DeleteMembers() {
        System.out.println("请输入删除会员信息的帐号:");
        String acc=sc.next();
        int flag=0;
        try{
            String sql="delete from members where Account=?";
            String sql1="select * from members where Account=?";
            ps1=con.prepareStatement(sql1);
            ps1.setString(1,acc);
            rs=ps1.executeQuery();

            while(rs.next()){
                flag=1;
                String acco=rs.getString("Account");
                String name=rs.getString("Name");
                String sex=rs.getString("Sex");
                String tel=rs.getString("Tel");
                Double balance=rs.getDouble("Balance");
                System.out.println(acco+"       "+name+"     "+sex+"    "+tel+"   "+balance);
            }
            if(flag==0){
                System.out.println("查无此人，删除信息失败！");
                return;
            }
            ps1.close();
            rs.close();
            System.out.println("是否删除？（是 1/否 2）");
            int x=sc.nextInt();
            if(x==1){
                ps=con.prepareStatement(sql);
                ps.setString(1,acc);
                int t=ps.executeUpdate();
                if(t>0) {
                    System.out.println("删除信息成功！");
                }else {
                    System.out.println("删除信息失败！");
                }
                ps.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void UpdateMembers() {
        System.out.println("请输入修改会员信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from members where Account=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Account" + "     " + "Name" + "   " + "Sex" + "     " + "Tel"+ "     " +"Balance");
                System.out.println(rs.getString("Account")+"     "+rs.getString("Name")+"\t"+rs.getString("Sex")+"\t"+rs.getString("Tel")+"\t"+rs.getDouble("Balance"));
                flag=0;
            }
            if(flag==1) {
                System.out.println("查无此人！");
            }
            System.out.println("请输入修改后的信息：");
            System.out.println("名字:");
            String name = sc.next();
            System.out.println("性别:");
            String sex = sc.next();
            System.out.println("电话:");
            String tel = sc.next();
            System.out.println("余额:");
            Double balance=sc.nextDouble();
            String sql1="update members set Name=?,Sex=?,Tel=?,Balance=? where Account=?";
            ps=con.prepareStatement(sql1);
            ps.setString(1,name);
            ps.setString(2,sex);
            ps.setString(3,tel);
            ps.setDouble(4,balance);
            ps.setString(5,acc);
            int t=ps.executeUpdate();
            if(t>0) {
                System.out.println("修改信息成功！");
            }else {
                System.out.println("查无此帐号，修改信息失败！");
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void AddMembers() {
        System.out.println("会员账号随机生成");
        String account = "";
        Random random = new Random();
        for (int i = 0; i < 8; i++) {
            account += String.valueOf(random.nextInt(8));
        }
        System.out.println("会员密码初始值为123456");
        String pass="123456";
        System.out.println("请输入添加会员的名字:");
        String name = sc.next();
        System.out.println("请输入添加会员的性别:");
        String sex = sc.next();
        System.out.println("请输入添加会员的电话:");
        String tel = sc.next();
        System.out.println("请输入添加会员的初始余额:");
        Double balance=sc.nextDouble();
        Members member=new Members(account,pass,name,sex,tel,balance);
        try{
            String sql= "insert into members(Account,Password,Name,Sex,Tel,Balance) values(?,?,?,?,?,?)";
            ps=con.prepareStatement(sql);
            ps.setString(1,member.getAccount());
            ps.setString(2,member.getPassword());
            ps.setString(3,member.getName());
            ps.setString(4,member.getSex());
            ps.setString(5,member.getTel());
            ps.setDouble(6,member.getBalance());
            if(!ps.execute())
            {
                System.out.println("添加会员信息成功！");
                return;
            }
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("添加会员信息失败！");
    }

    public static void ShowMembers() {
        System.out.println("Account" + "       " + "Name" + "      " + "Sex" + "       " + "Tel"+ "      " +"Balance");
        String sql="select * from members";
        try{
            ps=con.prepareStatement(sql);
            rs=ps.executeQuery();

            while(rs.next()) {
                String acco=rs.getString("Account");
                String name=rs.getString("Name");
                String sex=rs.getString("Sex");
                String tel=rs.getString("Tel");
                Double balance=rs.getDouble("Balance");
                System.out.println(acco+"       "+name+"     "+sex+"    "+tel+"   "+balance);
            }
            rs.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void CourseLogin() {
        System.out.println("请选择你要执行的操作：");
        System.out.println("1：浏览所有课程信息");
        System.out.println("2：增加课程信息");
        System.out.println("3：删除课程信息");
        System.out.println("4：查询课程信息");
        System.out.println("5：修改课程信息");
        System.out.println("6：退出");
        int x=sc.nextInt();
        switch(x){
            case 1:ShowCourse();break;
            case 2:AddCourse();break;
            case 3:DeleteCourse();break;
            case 4:QueryCourse();break;
            case 5:UpdateCourse();break;
            case 6:return;
        }
    }

    public static void UpdateCourse() {
        System.out.println("请输入修改课程信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from course where Number=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Number" + "   " + "courseName" + "   " + "Coach" + "  " + "Time"+ "      " +"Date"+"      "+"Price");
                System.out.println(rs.getString("Number")+"     "+rs.getString("courseName")+"     \t"+rs.getString("Coach")+"\t"+rs.getString("Time")+"\t"+rs.getString("Date")+"\t"+rs.getDouble("Price"));
                flag=0;
            }
            if(flag==1) {
                System.out.println("查无此课程！");
            }
            System.out.println("请输入修改后的信息：");
            System.out.println("名字:");
            String name = sc.next();
            System.out.println("教练:");
            String coach = sc.next();
            System.out.println("时间:");
            String time = sc.next();
            System.out.println("开课日期:");
            String date = sc.next();
            System.out.println("价格:");
            Double price=sc.nextDouble();
            String sql1="update course set courseName=?,Coach=?,Time=?,Date=?,Price=? where Number=?";
            ps=con.prepareStatement(sql1);
            ps.setString(1,name);
            ps.setString(2,coach);
            ps.setString(3,time);
            ps.setString(4,date);
            ps.setDouble(5,price);
            ps.setString(6,acc);
            int t=ps.executeUpdate();
            if(t>0) {
                System.out.println("修改信息成功！");
            }else {
                System.out.println("查无此课程，修改信息失败！");
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void QueryCourse() {
        System.out.println("请输入查找课程信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from course where Number=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Number" + "   " + "courseName" + "   " + "Coach" + "  " + "Time"+ "      " +"Date"+"      "+"Price");
                System.out.println(rs.getString("Number")+"     "+rs.getString("courseName")+"     \t"+rs.getString("Coach")+"\t"+rs.getString("Time")+"\t"+rs.getString("Date")+"\t"+rs.getDouble("Price"));
                flag=0;
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
        if(flag==1) {
            System.out.println("查无此课程！");
        }
    }

    public static void DeleteCourse() {
        System.out.println("请输入删除课程信息的编号:");
        String acc=sc.next();
        int flag=0;
        try{
            String sql="delete from course where Number=?";
            String sql1="select * from course where Number=?";
            ps1=con.prepareStatement(sql1);
            ps1.setString(1,acc);
            rs=ps1.executeQuery();

            while(rs.next()){
                flag=1;
                String num=rs.getString("Number");
                String name=rs.getString("courseName");
                String coach=rs.getString("Coach");
                String time=rs.getString("Time");
                String date=rs.getString("Date");
                Double price=rs.getDouble("Price");
                System.out.println(num+"       "+name+"     "+coach+"   "+time+"   "+date+"     "+price);
            }
            if(flag==0){
                System.out.println("查无此课，删除信息失败！");
                return;
            }
            ps1.close();
            rs.close();
            System.out.println("是否删除？（是 1/否 2）");
            int x=sc.nextInt();
            if(x==1){
                ps=con.prepareStatement(sql);
                ps.setString(1,acc);
                int t=ps.executeUpdate();
                if(t>0) {
                    System.out.println("删除信息成功！");
                }else {
                    System.out.println("删除信息失败！");
                }
                ps.close();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void AddCourse() {
        System.out.println("请输入待添加的课程编号：");
        String num = sc.next();
        System.out.println("请输入待添加的课程名称：");
        String name= sc.next();
        System.out.println("请输入添加课程的教练:");
        String coach = sc.next();
        System.out.println("请输入添加课程的时间:");
        String time = sc.next();
        System.out.println("请输入添加课程的上课日期:");
        String date = sc.next();
        System.out.println("请输入添加课程的价格:");
        Double price=sc.nextDouble();
        Course c=new Course(num,name,coach,time,date,price);

        try{
            String sql= "insert into course(Number,courseName,Coach,Time,Date,Price) values(?,?,?,?,?,?)";
            ps=con.prepareStatement(sql);
            ps.setString(1,c.getNumber());
            ps.setString(2,c.getCourseName());
            ps.setString(3,c.getCoach());
            ps.setString(4,c.getTime());
            ps.setString(5,c.getDay());
            ps.setDouble(6,c.getPrice());
            if(!ps.execute())
            {
                System.out.println("添加课程信息成功！");
                return;
            }
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("添加课程信息失败！");
    }

    public static void ShowCourse() {
        System.out.println("Number" + "   " + "courseName" + "   " + "Coach" + "  " + "Time"+ "      " +"Date"+"      "+"Price");
        String sql="select * from course";
        try{
            ps=con.prepareStatement(sql);
            rs=ps.executeQuery();

            while(rs.next()) {
                String num=rs.getString("Number");
                String name=rs.getString("courseName");
                String coach=rs.getString("Coach");
                String time=rs.getString("Time");
                String date=rs.getString("Date");
                Double price=rs.getDouble("Price");
                System.out.println(num+"       "+name+"     "+coach+"   "+time+"   "+date+"     "+price);
            }
            rs.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void CoachLogin() {
        System.out.println("请选择你要执行的操作：");
        System.out.println("1：浏览所有教练信息");
        System.out.println("2：增加教练信息");
        System.out.println("3：删除教练信息");
        System.out.println("4：查询教练信息");
        System.out.println("5：修改教练信息");
        System.out.println("6：退出");
        int x=sc.nextInt();
        switch(x){
            case 1:ShowCoach();break;
            case 2:AddCoach();break;
            case 3:DeleteCoach();break;
            case 4:QueryCoach();break;
            case 5:UpdateCoach();break;
            case 6:return;
        }
    }

    public static void UpdateCoach() {
        System.out.println("请输入修改教练信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from coach where Number=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Number" + "   " + "Name" + "   " + "Sex" + "       " + "Tel"+ "        " +"Level");
                System.out.println(rs.getString("Number")+"     "+rs.getString("Name")+"\t"+rs.getString("Sex")+"\t"+rs.getString("Tel")+"   \t"+rs.getString("Level"));
                flag=0;
            }
            if(flag==1) {
                System.out.println("查无此人！");
            }
            System.out.println("请输入修改后的信息：");

            System.out.println("名字:");
            String name = sc.next();
            System.out.println("性别:");
            String sex = sc.next();
            System.out.println("电话:");
            String tel = sc.next();
            System.out.println("级别:");
            String lev=sc.next();
            String sql1="update coach set Name=?,Sex=?,Tel=?,Level=? where Number=?";
            ps=con.prepareStatement(sql1);
            ps.setString(1,name);
            ps.setString(2,sex);
            ps.setString(3,tel);
            ps.setString(4,lev);
            ps.setString(5,acc);
            int t=ps.executeUpdate();
            if(t>0) {
                System.out.println("修改信息成功！");
            }else {
                System.out.println("查无此帐号，修改信息失败！");
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void QueryCoach() {
        System.out.println("请输入查找教练信息的帐号:");
        String acc=sc.next();
        int flag=1;
        try {
            String sql="select * from coach where Number=?";
            ps=con.prepareStatement(sql);
            ps.setString(1,acc);
            rs=ps.executeQuery();
            while(rs.next()) {
                System.out.println("Number" + "   " + "Name" + "   " + "Sex" + "       " + "Tel"+ "        " +"Level");
                System.out.println(rs.getString("Number")+"     "+rs.getString("Name")+"\t"+rs.getString("Sex")+"\t"+rs.getString("Tel")+"   \t"+rs.getString("Level"));
                flag=0;
            }
            ps.close();
            rs.close();
        }catch(Exception e) {
            e.printStackTrace();
        }
        if(flag==1) {
            System.out.println("查无此人！");
        }
    }

    public static void DeleteCoach() {
        System.out.println("请输入删除教练信息的编号:");
        String acc=sc.next();
        try{
            String sql="delete from coach where Number=?";
            String sql1="select * from coach where Number=?";
            ps1=con.prepareStatement(sql1);
            ps1.setString(1,acc);
            rs=ps1.executeQuery();
            while(rs.next()){
                System.out.println("当前要删除信息：");
                String num=rs.getString("Number");
                String name=rs.getString("Name");
                String sex=rs.getString("Sex");
                String tel=rs.getString("Tel");
                String level=rs.getString("Level");

                System.out.println(num+"       "+name+"     "+sex+"    "+tel+"   "+level);
            }
            ps1.close();
            rs.close();
            System.out.println("是否删除？（是 1/否 2）");
            int x=sc.nextInt();
            if(x==1){
                ps=con.prepareStatement(sql);
                ps.setString(1,acc);
                int t=ps.executeUpdate();
                if(t>0) {
                    System.out.println("删除信息成功！");
                }else {
                    System.out.println("查无此人，删除信息失败！");
                }
                ps.close();
            }
            else{
                return;
            }



        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void AddCoach() {
        System.out.println("请输入教练员编号");
        String num=sc.next();
        System.out.println("请输入添加教练的名字:");
        String name = sc.next();
        System.out.println("请输入添加教练的性别:");
        String sex = sc.next();
        System.out.println("请输入添加教练的电话:");
        String tel = sc.next();
        System.out.println("请输入添加教练的级别:");
        String level=sc.next();
        Coach c=new Coach(num,name,sex,tel,level);
        try{
            String sql= "insert into coach(Number,Name,Sex,Tel,Level) values(?,?,?,?,?)";
            ps=con.prepareStatement(sql);
            ps.setString(1,c.getCoachNumber());

            ps.setString(2,c.getCoachName());
            ps.setString(3,c.getSex());
            ps.setString(4,c.getTel());
            ps.setString(5,c.getLevel());
            if(!ps.execute())
            {
                System.out.println("添加教练信息成功！");
                return;
            }
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("添加教练信息失败！");
    }

    public static void ShowCoach() {
        System.out.println("Number" + "     " + "Name" + "     " + "Sex" + "       " + "Tel"+ "        " +"Level");
        String sql="select * from coach";
        try{
            ps=con.prepareStatement(sql);
            rs=ps.executeQuery();

            while(rs.next()) {
                String num=rs.getString("Number");
                String name=rs.getString("Name");
                String sex=rs.getString("Sex");
                String tel=rs.getString("Tel");
                String level=rs.getString("Level");

                System.out.println(num+"       "+name+"     "+sex+"    "+tel+"   "+level);
            }
            rs.close();
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
